//
//  Request.m
//  WorkUI-17
//
//  Created by lanou3g on 15/7/1.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "Request.h"

@implementation Request


//实现封装函数
-(void)requestWithUrl:(NSString *)urlStr
{
    //1.创建一个url对象(把网址字符串转换成url)
    NSURL *url = [NSURL URLWithString:urlStr];
    //2.创建一个请求对象
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    //3.发送异步请求
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        //实现代理传值
        //若请求成功则调用成功的函数
        if (data) {
            [_delegate requestSucess:data];
        }
        //若请求失败则调用失败的函数
        if (connectionError) {
            [_delegate requestError:connectionError];
        }
        
    }];
}
@end
